package AdminClient;

import AdminClient.*;
import java.util.Timer;

public class AdminControl {
	AdminInfo admin;
	boolean done = false;
	AdminGUI gui;
	public static void main(String [] args) {
		AdminControl control = new AdminControl();
		control.run_admin();
	}
	public void run_admin()
	{
		admin = new AdminInfo();
		//GUI_Thread gui = new GUI_Thread();
		//gui.start();
		
		gui=new AdminGUI(admin);
		
		ServerInterface server_interface = new ServerInterface(admin);
		admin.set_server(server_interface);
		admin.set_gui(gui);
		gui.setLocationRelativeTo(null);
		gui.setVisible(true);
		server_interface.start();
		
		//Server_Thread si = new Server_Thread();
		//si.start();
		while(!admin.done)
		{
		}
		
		System.out.println("Exiting Program");
		Thread t = new Thread();
		try{
			t.sleep(3000);
		} catch (InterruptedException e) {
			System.out.println("Timer Error");
		}
		
		System.exit(0);
		//try {
			//gui.sleep(5000);
		//} catch (Exception e) {
		//	System.out.println("Ending Error");
		//}
		//si.stop();
		//gui.stop();
	}
	
	public class Server_Thread extends Thread
	{
		public void run()
		{
			ServerInterface server_interface = new ServerInterface(admin);
			admin.set_server(server_interface);
			server_interface.start();
			while(!server_interface.done)
			{
				try {
					sleep(500);
				} catch (InterruptedException e) {
					System.out.println("Error Starting Server Interface");
				}
			}
			server_interface.stop();
			//server_interface.run_interface();
		}
	}
	
	public class GUI_Thread extends Thread
	{
		public void run()
		{
			try {
				sleep(4000);
			} catch (InterruptedException e) {
				System.out.println("Error Starting Interface");
			}
			AdminInterface admin_interface = new AdminInterface(admin);
			admin_interface.start();
			while(!admin_interface.done)
			{
				try{
					sleep(500);
				}catch (InterruptedException e){
					System.out.println("GUI_Thread Not Sleeping");
				}
			}
			admin_interface.stop();
			done = true;
		}
	}
}
